home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / SAT Invaders demo ƒ / sShot.p < prev   
Text File  |  1994-08-21  |  1KB  |  61 lines

  1. {===============================================}
  2. {================= Shot sprite unit ================}
  3. {===============================================}
  4.  
  5. { Example file for Ingemars Sprite Animation Toolkit. }
  6. { © Ingemar Ragnemalm 1992 }
  7. { See doc files for legal terms for using this code. }
  8.  
  9. unit sShot;
  10.  
  11. { Sprite unit. A sprite unit should include the following routines:}
  12. { Init-procedure, that initializes private bitmaps}
  13. { Setup-procedure, that sets variables other than the standard ones set by MakeSprite }
  14. { Handle-procedure, to be called once per iteration until the sprite dies }
  15. { Hittask-procedure (optional), for advanced collission handling. }
  16.  
  17. { Shot object for the SATInvaders sample game. }
  18.  
  19. interface
  20.  
  21.     uses
  22.         SAT, SoundConst, GameGlobals;
  23.  
  24.     procedure InitShot;
  25.     procedure SetupShot (sp: SpritePtr);
  26.     procedure HandleShot (me: SpritePtr);
  27.  
  28. implementation
  29.  
  30.     const
  31.         shotSpeed = 15;
  32.  
  33.     var
  34.         shotFace: FacePtr;
  35.  
  36.     procedure InitShot;
  37.     begin
  38.         shotFace := SATGetFace(135);
  39.     end;
  40.  
  41.     procedure SetupShot (sp: SpritePtr);
  42.     begin
  43.         sp^.face := shotFace;
  44.         SetRect(sp^.hotRect, 0, 0, 8, 12); {How big are we?}
  45.         sp^.task := @HandleShot;
  46.     end;
  47.  
  48.     procedure HandleShot (me: SpritePtr);
  49.     begin
  50.         if me^.kind <> 1 then {Hit something - remove}
  51.             begin
  52.                 me^.task := nil;
  53. {No sound here - we assume that the bad guys (sEnemy and sMissile) do that }
  54.             end;
  55.  
  56.         me^.position.v := me^.position.v - shotSpeed;
  57.         if me^.position.v < 0 then
  58.             me^.task := nil; {Outside - remove}
  59.     end;
  60.  
  61. end.